package com.wangyu.springsecuritydemo.entity.primary;

import com.wangyu.springsecuritydemo.entity.BaseEntity;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

/**
 * @Author wangyu
 * @Date 2019/2/18 16:22
 * @Version 1.0
 */
@Entity
@Table(name = "sys_role")
public class RoleEntity extends BaseEntity {

  /**
   * serialVersionUID
   */
  private static final long serialVersionUID = -1571980488758408855L;

  /**
   * 角色名
   */
  @Column(name = "name", nullable = false)
  private String name;

  /**
   * 1:正常  0: 禁用 默认为正常
   */
  @Column(name = "status", length = 32)
  private String status = "1";

  /**
   * 与用户多对多关联
   */
  @ManyToMany(fetch = FetchType.LAZY)
  @JoinTable(name = "sys_role_user", joinColumns = {
      @JoinColumn(name = "role_id")}, inverseJoinColumns = {@JoinColumn(name = "user_id")})
  private Set<UserEntity> users;

  /**
   * 与权限多对多
   */
  @ManyToMany(fetch = FetchType.LAZY)
  @JoinTable(name = "sys_role_permission", joinColumns = {
      @JoinColumn(name = "role_id")}, inverseJoinColumns = {@JoinColumn(name = "permission_id")})
  private Set<PermissionEntity> permissions;

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getStatus() {
    return status;
  }

  public void setStatus(String status) {
    this.status = status;
  }

  public Set<UserEntity> getUsers() {
    return users;
  }

  public void setUsers(Set<UserEntity> users) {
    this.users = users;
  }

  public Set<PermissionEntity> getPermissions() {
    return permissions;
  }

  public void setPermissions(
      Set<PermissionEntity> permissions) {
    this.permissions = permissions;
  }
}
